package cn.bytecollege.controller;

import cn.bytecollege.model.Orders;
import cn.bytecollege.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/pay")
public class PayController {
    @Autowired
    private OrdersService ordersService;


    @RequestMapping("/toPay")
    public String toPay(Integer ordersId,
                        Model model) {


        Double totalPrice = ordersService.getTotalPrice(ordersId);
        model.addAttribute("totalPrice", totalPrice);
        model.addAttribute("ordersId", ordersId);
        return "pay";
    }

    @RequestMapping("/payNow")
    public String payNow(@RequestParam("ordersId") Integer ordersId) {
        ordersService.payNow(ordersId);
        return "redirect:/user/getOrder";
    }

    @RequestMapping("/payAfter")
    public String payAfter() {
        return "redirect:/user/getOrder";
    }
}
